<template>
	<view @click="handClick">
		<slot></slot>
	</view>
</template>

<script>
	export default {
		props: {
			//检测是否登陆
			checkLogin: {
				type: Boolean,
				default: true
			},
			//检测是否是志愿者
			checkVol: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {

			};
		},

		methods: {
			handClick() {
				if (!this.store_user_code) {
					this.navigateTo({
						url: this.getUrlAndParam()
					}, {
						login: true // 需要校验是否登录
					})
					return;
				}
				if (!this.store_is_vol && this.checkVol) {
					uni.$emit('show-auth-vol');
					return;
				}
				this.$emit("click");
			},
			//获取当前页面路由以及参数
			getUrlAndParam() {
				let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
				let curRoute = routes[routes.length - 1].route; // 获取当前页面路由，也就是最后一个打开的页面路由
				let curParam = routes[routes.length - 1].options; //获取路由参数     //   {"userId":"1000007"}
				let param = ''
				for (let key in curParam) {
					param += '&' + key + '=' + curParam[key]
				}
				return (curRoute + "?" + param).replace("?&", "?");
			}
		}
	}
</script>

<style>
</style>
